package com.aep.provisioning.annotations.controller.validator;

import org.springframework.stereotype.Service;
import org.springframework.validation.Errors;

import com.aep.provisioning.controller.form.ContactForm;
import com.aep.provisioning.util.BaseValidatorImpl;

@Service("contactValidator")
public class ContactValidator extends BaseValidatorImpl{

	@Override
	protected Class<ContactForm> getValidatorSupportClass() {
		return ContactForm.class;
	}
	
	@Override
	public void validate(Object object, Errors errors) {
		validateBeanForm(object, errors);
	}

	public void validateBeanForm(Object object, Errors errors) {
		
		ContactForm contactForm = (ContactForm) object;
		if(contactForm.getName()== null || contactForm.getName().isEmpty()){
			errors.rejectValue("name","error.required", "Name is required.");
		}
		if(contactForm.getPhone()==null || contactForm.getName().isEmpty()){
			errors.rejectValue("phone","error.required", "Phone is required");
		}
		if(contactForm.getReasonDescriptions() == null || contactForm.getReasonDescriptions().size()<1){
			errors.rejectValue("reasonDescriptions","error.required", "Select a minimum interest.");
		}
		
	}
	
}
